<template>
  <el-dropdown trigger="click" @command="handleSetLanguage">
    <div>
      <svg-icon class-name="size-icon" icon-class="language" />
    </div>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item v-for="item of languageOptions" :key="item.value" :disabled="language===item.value" :command="item.value">
        {{ item.label }}
      </el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
export default {
  data() {
    return {
      languageOptions: [
        { label: '简体中文', value: 'zh-CN' },
        { label: 'English', value: 'en-US' }
      ]
    }
  },
  computed: {
    language() {
      return this.$store.state.app.language
    }
  },
  methods: {
    handleSetLanguage(language) {
      this.$store.dispatch('app/setLanguage', language)
      this.$message({
        message: this.language === 'zh-CN' ? '切换成功，正在刷新' : 'Switch Language Success',
        type: 'success'
      })
      setTimeout(() => {
        window.location.reload()
      },500)
    }
  }

}
</script>